package com.wugui.datatx.core.util;

import lombok.Data;

/**
 * sharding vo
 *
 * @author xuxueli 2017-07-25 21:26:38
 */
public class ShardingUtil {

  private static final InheritableThreadLocal<ShardingVO> CONTEXT_HOLDER =
      new InheritableThreadLocal<>();

  public static ShardingVO getShardingVo() {
    return CONTEXT_HOLDER.get();
  }

  public static void setShardingVo(ShardingVO shardingVo) {
    CONTEXT_HOLDER.set(shardingVo);
  }

  @Data
  public static class ShardingVO {

    private int index; // sharding index
    private int total; // sharding total

    public ShardingVO(int index, int total) {
      this.index = index;
      this.total = total;
    }
  }
}
